package com.wewins.fota.bean.bo;

import lombok.Data;

import java.text.DecimalFormat;
import java.time.Duration;

@Data
public class StatInfo {
    private String api;

    private double cost;

    private double frequency;

    private Duration statTimeRange;

    public StatInfo withStatTimeRange(Duration duration) {
        this.statTimeRange = duration;
        return this;
    }

    public String toLog() {
        String frequency = new DecimalFormat("0.00")
                .format(this.frequency / this.statTimeRange.toMillis() * 1000);
        return "api:[" + this.api + "], " +
                "current frequency is [" + frequency + "] pics/s, " +
                "avg cost: [" + this.cost + "]ms";
    }
}
